﻿/************************************************
*
* Copyright(c) ZeeGuo.com
*
* CLR : 4.0.30319.296
*
* FileName : Entity4399ComicBookList.cs
*
* Author : Kurodo
*
* CreatTime : 2013/7/23 17:01:16
*           
*************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ComicSpider.Model;
using HtmlAgilityPack;

namespace ComicSite
{
    public class Entity4399ComicBookList : EntityComicBookList
    {
        protected override string GetWebSiteUrl()
        {
            return "http://dm.4399.com/manhua";
        }

        protected override string GetKeyCode(string context)
        {
            return string.Empty;
        }

        protected override string GetAuthor(string context)
        {
            return DataMatch.RegexsValue(context, "<li>作者：<span>(\\w{1,10})</span></li>", 1);
        }

        protected override string GetAddress(string context)
        {
            return string.Empty;
        }

        protected override string GetState(string context)
        {
            return DataMatch.RegexsValue(context, "<li>连载状态：<a href=\"/search/mh[\\-\\d{1,1}]*/\">(\\w{1,10})</a></li>", 1);
        }

        protected override string GetSubject(string context)
        {
            return DataMatch.RegexsValue(context, "类型：<a href=\"/search/mh[\\-\\d{1,1}]*/\">(\\w{1,10})", 1);
        }

        protected override string GetCategory(string context)
        {
            return string.Empty;
        }

        protected override string GetUpdate(string context)
        {
            return string.Empty;
            //DataMatch.RegexsValue(context, "预计\\d{1,1}月\\d{1,2}日更新", 0);
        }

        //protected override string GetIntroduction(string context)
        //{
        //    return base.GetIntroduction(context);
        //}

        protected override string GetHotNum(string context)
        {
            return string.Empty;
        }

        protected override string GetBookName(string context)
        {
            return DataMatch.RegexsValue(context, "<div class=\"dm_hd\"><h2>(\\w{1,10})</h2>", 1);
        }

        protected override string GetOldName(string context)
        {
            return string.Empty;
        }

        protected override string GetOtherName(string context)
        {
            return string.Empty;
        }

        public override List<EntityComicBook> GetComicList(string context)
        {
            List<EntityComicBook> list = new List<EntityComicBook>();
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(context);

            HtmlNode html = doc.DocumentNode;
            HtmlNodeCollection books = html.SelectNodes("//div[@class='g_listbx']//a[@href]");
            if (books != null)
            {
                foreach (HtmlNode link in books)
                {
                    HtmlAttribute att = link.Attributes["href"];
                    Entity4399ComicBook comics = new Entity4399ComicBook();
                    comics.UrlAddress = string.Format("{0}{1}", this.Comic_WebSiteUrl, att.Value);
                    comics.Comic_BookName = link.InnerText;
                    list.Add(comics);
                }
            }

            return list;
        }
    }
}
